home *** CD-ROM | disk | FTP | other *** search
-
- /* Example of EasyRequest using BuildEasyRequestArgs */
-
- x = addlib("apig.library",0,-30,0)
-
- call set_apig_globals()
-
- portname = "easyreq4_port"
- p = openport(portname)
-
- WaitForPort portname
-
- wintitle = "Build Easy Requester Example"
- winidcmp = IDCMP_CLOSEWINDOW
- winflags = WFLG_CLOSEGADGET+WFLG_DRAGBAR+WFLG_SIZEGADGET+WFLG_DEPTHGADGET+WFLG_GIMMEZEROZERO
- win = openwindow(portname,0,0,640,200,2,4,winidcmp,winflags,wintitle,null(),0,0,0)
-
- /* now we need to make args for BuildEasy... */
-
- /* allocate an EasyStruct structure */
- easystruct = MAKESTRUCT(0,29,0,MEMF_CLEAR) /* type 29 is an EasyStruct */
- /* see docs */
- /* EasyStruct looks like this:
- byte offset 0 es_StructSize ULONG
- 4 es_Flags ULONG
- 8 es_Title UBYTE *
- 12 es_TextFormat UBYTE *
- 16 es_GadgetFormat UBYTE *
- size = 20
- ---------------------------------------------------------------- */
-
- /* make our arglist, which is owned by the easystruct */
- arglist = MAKEPOINTER(easystruct,0,64,MEMF_CLEAR)
-
- call SETVALUE(arglist,0,4,'n',22) /* I'm just stuffing some random */
- call SETVALUE(arglist,4,4,'n',32) /* values into the args, nothing */
- call SETVALUE(arglist,8,4,'n',42) /* special about these values */
-
- call SETVALUE(arglist,12,4,'n',1) /* These are the gadget numbers */
- call SETVALUE(arglist,16,4,'n',2)
- call SETVALUE(arglist,20,4,'n',0)
-
- reqtitle = "This is your EasyRequester"
-
- reqtext = "Say Buddy If You Insert or Remove a Disk ..." '0a'x '0a'x
- reqtext = reqtext || " ... I'll go away %ld %ld %ld " '0a'x '0a'x
- reqtext = reqtext || " YOU REALLY MUST INSERT/REMOVE A DISK !!! " '0a'x
-
- gadtext = " %ld). OKAY | %ld). MAYBE | %ld). NOWAY "
-
- /* make buffers for title/text/gadget, the memory allocated will be 'owned'
- by easystruct */
-
- titleptr = MAKEPOINTER(easystruct,0,length(reqtitle)+1,MEMF_CLEAR)
- textptr = MAKEPOINTER(easystruct,0,length(reqtext)+1,MEMF_CLEAR)
- gadgetptr = MAKEPOINTER(easystruct,0,length(gadtext)+1,MEMF_CLEAR)
-
- call export(titleptr,reqtitle)
- call export(textptr,reqtext)
- call export(gadgetptr,gadtext)
-
- call SETVALUE(easystruct,0,4,'n',20) /* es->es_StructSize */
- call SETVALUE(easystruct,4,4,'n',0) /* es->es_Flags */
- call SETVALUE(easystruct,8,4,'p',titleptr) /* es->es_Title */
- call SETVALUE(easystruct,12,4,'p',textptr) /* es->es_TextFormat */
- call SETVALUE(easystruct,16,4,'p',gadgetptr) /* es->es_GadgetFormat */
-
- reqx = BUILDEASYREQUESTARGS(win,easystruct,IDCMP_DISKINSERTED+IDCMP_DISKREMOVED,arglist)
-
- /* idcmpptr is where IDCMP value is returned */
- idcmpptr = makepointer(easystruct,0,4,MEMF_CLEAR)
-
- wearedone = 0
- do while wearedone = 0
-
- sysreqx = SYSREQHANDLER(reqx,idcmpptr,1) /* ... and wait */
-
- /* sysreqx = SYSREQHANDLER(reqx,idcmpptr,0) ... if you do this then */
- /* sysreqhandler will NOT WAIT */
-
- select
- when sysreqx = -2 then iterate
-
- when sysreqx = -1 then /* satisfied by IDCMP, unlike EASYREQUEST() */
- /* I dont give you the negative value, you */
- /* have to look in *idcmpptr. */
- do
- idcmp = GETVALUE(idcmpptr,0,4,'n')
- select
- when idcmp = IDCMP_DISKINSERTED then
- do
- say "I see you Inserted a DISK"
- wearedone = 1
- end
- when idcmp = IDCMP_DISKREMOVED then
- do
- say "I see you Removed a DISK"
- wearedone = 1
- end
- otherwise nop
- end
- end
- otherwise
- do
- select
- when sysreqx = 1 then say " 'OKAY' ... is OKAY with me too !"
- when sysreqx = 2 then say " 'MAYBE' ... not sure uh ? "
- when sysreqx = 0 then say " 'NOWAY' ... I'm outta here !"
- otherwise nop
- end
- end
- end
-
- end
-
- call FREETHIS(easystruct) /* title/text/gadget buffers freed too! */
- call FREESYSREQUEST(reqx)
- call CLOSEWINDOW(win)
-
- exit
-